﻿/// Write a program that finds in given array of integers a sequence of given sum S (if present). 
/// Example:	 {4, 3, 1, 4, 2, 5, 8}, S=11  {4, 2, 5}	



using System;

class zad_10
{
    static void Main()
    {
        int[] arr = { 4, 3, 1, 4, 2, 5, 8 }; //{ 4, 1, 1, 4, 2, 3, 4, 4, 1, 2, 4, 9, 3 }; //{ 2, 2, 2, 1, 1, 2, 3, 3, 3, 3, 3, 3, 2, 2, 2, 1, 5 };

        int sum = 0;
        int machSum = 11; // S sum
        int startIndex = 0;
        int endIndex = 0;
        int lenght = arr.Length;

        for (int i = 0; i < lenght; i++)
        {
            for (int j = i; j < lenght; j++)
            {
                sum += arr[j];

                if (machSum == sum)
                {
                    machSum = sum;
                    startIndex = i;
                    endIndex = j;
                }
            }
            sum = 0;
        }

        Console.WriteLine(machSum);
        //Console.WriteLine(startIndex + " " + endIndex);

        for (int i = startIndex; i <= endIndex; i++)
        {
            Console.Write(arr[i] + " ");
        }

        Console.WriteLine();
    }
}
